package com.ruoyi.info.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.info.mapper.VinfoUnitMapper;
import org.springframework.stereotype.Service;
import com.ruoyi.info.mapper.VinfoCompanyMapper;
import com.ruoyi.info.domain.VinfoCompany;
import com.ruoyi.info.service.IVinfoCompanyService;

import javax.annotation.Resource;

/**
 * 企业信息Service业务层处理
 *
 * @author oy
 * @date 2022-12-16
 */
@Service
public class VinfoCompanyServiceImpl implements IVinfoCompanyService
{
    @Resource
    private VinfoCompanyMapper vinfoCompanyMapper;

    @Resource
    private VinfoUnitMapper vinfoUnitMapper;

    /**
     * 查询企业信息
     *
     * @param compId 企业信息主键
     * @return 企业信息
     */
    @Override
    public VinfoCompany selectVinfoCompanyByCompId(Long compId)
    {
        return vinfoCompanyMapper.selectVinfoCompanyByCompId(compId);
    }

    /**
     * 查询企业信息列表
     *
     * @param vinfoCompany 企业信息
     * @return 企业信息
     */
    @Override
    public List<VinfoCompany> selectVinfoCompanyList(VinfoCompany vinfoCompany,long userId)
    {
        return vinfoCompanyMapper.selectVinfoCompanyList(vinfoCompany,userId);
    }

    /**
     * 新增企业信息
     *
     * @param vinfoCompany 企业信息
     * @return 结果
     */
    @Override
    public int insertVinfoCompany(VinfoCompany vinfoCompany)
    {
        long userId = SecurityUtils.getUserId();
        long unitId = vinfoUnitMapper.selectUnitIdByUserId(userId);
        return vinfoCompanyMapper.insertVinfoCompany(vinfoCompany,unitId);
    }

    /**
     * 修改企业信息
     *
     * @param vinfoCompany 企业信息
     * @return 结果
     */
    @Override
    public int updateVinfoCompany(VinfoCompany vinfoCompany)
    {
        return vinfoCompanyMapper.updateVinfoCompany(vinfoCompany);
    }

    /**
     * 批量删除企业信息
     *
     * @param compIds 需要删除的企业信息主键
     * @return 结果
     */
    @Override
    public int deleteVinfoCompanyByCompIds(Long[] compIds)
    {
        return vinfoCompanyMapper.deleteVinfoCompanyByCompIds(compIds);
    }

    /**
     * 删除企业信息信息
     *
     * @param compId 企业信息主键
     * @return 结果
     */
    @Override
    public int deleteVinfoCompanyByCompId(Long compId)
    {
        return vinfoCompanyMapper.deleteVinfoCompanyByCompId(compId);
    }

    /**
     * 通过企业名称查询企业id和名称列表
     * @return
     */
    public List<Map<String,Object>> selectCompItems(long userId){
        return vinfoCompanyMapper.selectCompItems(userId);
    }
}
